<?php
/**
 * ==============================================
 * Copy right 2015-2016 http://wei.meididi88.com
 * ----------------------------------------------
 * This is not a free software, without any authorization is not allowed to use and spread.
 * ==============================================
 * @author: hy
 * @date: 2015-9-10
 * @version: v1.0.0
 */
namespace Home\Model;

use Think\Model;

/**
 * 美容师收支明细Model模型类
 */
class IncomeStatementModel extends Model{
	
	/**
	 * 美容师收支总数
	 * 
	 * @param number $id 美容师编号
	 * @return number
	 */
	public function beauticianIncomeTotal($id) {
		return $this->where(array('beautician_id' => $id))->count();
	}
	
	/**
	 * 查询美容师的收支明细
	 * 
	 * @param number $beauticianId	美容师编号
	 * @param number $offset		查询起始位置
	 * @param number $limit			查询条数
	 */
	public function getBeauticanIncome($beauticianId, $offset = 0, $limit = 8) {
		return $this->where(array('beautician_id' => $beauticianId))
			->order('created DESC')
			->limit($offset.','.$limit)
			->select();
	}
	
	/**
	 * 支出记录添加
	 * 
	 * @param number $beauticianId	美容师编号
	 * @param number $expend		支出金额
	 * @param string $remark		备注
	 */
	public function expend($beauticianId, $expend, $remark = '') {
		$incomeInfo = array(
			'beautician_id' => $beauticianId,
			'type' => 'expend',
			'expend' => $expend,
			'remark' => $remark,
			'created' => time()
		);
		
		return $this->add($incomeInfo);
	}
}